cmake_minimum_required(VERSION 2.8.3)
project(adas_front_vision)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lglog   std=c++11 -Wall -Ofast -pthread -lpthread  ")

set(CMAKE_C_FLAGS " -std=c11 -fPIE -fPIC -Wno-attributes ")
if (CMAKE_COMPILER_IS_GNUCXX)
	set(CMAKE_CXX_FLAGS "-O3 -Wall")
	set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11")
endif()


find_package(Glog REQUIRED)
find_package(OpenCV REQUIRED)
find_package(CUDA REQUIRED)
find_library(YAML_CPP_LIBRARIES yaml-cpp)
if(NOT YAML_CPP_LIBRARIES)
       find_package(yaml-cpp REQUIRED)
include_directories(${YAML_CPP_INCLUDE_DIRS})
endif(NOT YAML_CPP_LIBRARIES)


include_directories(
    ${PROJECT_SOURCE_DIR}/include
    ${Opencv_INCLUDE_DIRS}
    ${CUDA_INCLUDE_DIRS}
    ${Qt5Core_INCLUDE_DIRS}
    ${CMAKE_CURRENT_SOURCE_DIR}/../../../include
    $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/detection_vision>
    $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src/detection_vision>
    $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
)

set(CMAKE_BUILD_TYPE Release)
set(GPU_ARCHS 61)  ## config your GPU_ARCHS,See [here](https://developer.nvidia.com/cuda-gpus) for finding what maximum compute capability your specific GPU supports.
set(TENSORRT_ROOT /usr/local/TensorRT-5.0.2.6)

if(NOT TARGET onnx_proto)
  # Note: This avoids libprotobuf.so complaining about name collisions at runtime
  if(NOT ONNX_NAMESPACE)
    set(ONNX_NAMESPACE "onnx2trt_onnx")
  endif()
  add_definitions("-DONNX_NAMESPACE=${ONNX_NAMESPACE}")
  add_subdirectory(src/onnx EXCLUDE_FROM_ALL)
endif()

add_subdirectory(src/onnx-tensorrt)
add_subdirectory(src/detection_vision)
add_subdirectory(src/stereo_vision)
add_subdirectory(src/cmw_app)
add_subdirectory(src/detection)


add_executable(adas_front_vision_app app/front_vision_app.cpp)
target_link_libraries(adas_front_vision_app   ${OpenCV_LIBRARIES} sgm cmw_app)


######install params########
file(GLOB PARAMS  params/*)
set(CMAKE_STAGING_PREFIX /opt/adc)
install(FILES ${PARAMS} DESTINATION ${CMAKE_STAGING_PREFIX}/params)

file(GLOB MODELS  models/*)
install(FILES ${MODELS} DESTINATION ${CMAKE_STAGING_PREFIX}/models)

install(TARGETS adas_front_vision_app
   RUNTIME DESTINATION ${CMAKE_STAGING_PREFIX}/bin )



